home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / encrypt.arc / ENCRYPT.C next >
C/C++ Source or Header  |  1988-04-26  |  2KB  |  64 lines

  1.  
  2. /*                  ENCRYPTOR                     */
  3. /*      Compute!'s Atari ST Disk & Magazine           */
  4. /*        October 1986 -- Volume 1, No. 1                 */
  5. /*        = 1986 Compute Publications/ABC                 */
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <osbind.h>
  10.  
  11. main()
  12.   {
  13.         int   i = 0, c1;
  14.  
  15.         char  password[40], filename[40], c;
  16.         FILE  *fopen (), *file_ptr1, *file_ptr2;
  17.  
  18.         printf ( "What is the name of the file to be CRYPTed? " );
  19.         scanf  ( "%s", filename ); printf ( "\n" );
  20.         printf ( "What is the PASSWORD to be used? ");
  21.         scanf  ( "%s", password ); printf ( "\n" );
  22.  
  23.         file_ptr1 = fopen ( filename, "r" );
  24.  
  25.         if ( file_ptr1 == NULL)
  26.           {
  27.                 printf ( "Couldn't open %s for input.\n", filename );
  28.                 getchar();
  29.           }
  30.         else
  31.           {
  32.                 file_ptr2 = fopen ( "qqqq", "w" );
  33.  
  34.                 if ( file_ptr2 == NULL )
  35.                   {
  36.                         printf ( "Couldn't open output file.\n" );
  37.                         getchar();
  38.                   }
  39.                 else
  40.                   {
  41.                         while ( ( c = fgetc ( file_ptr1 ) ) != EOF )
  42.                           {
  43.                                 c1 = password[i] * 2 - c;
  44.                                 if ( c1 > 255 )
  45.                                   c1 -= 256;
  46.                                 if ( c1 < 0 )
  47.                                   c1 += 256;
  48.  
  49.                                 fputc ( c1, file_ptr2 );
  50.  
  51.                                 ++i;
  52.                                 if ( password[i] == '\0' )
  53.                                   i = 0;
  54.                           }
  55.  
  56.                         fclose ( file_ptr1 );
  57.                         fclose ( file_ptr2 );
  58.  
  59.                         Fdelete ( filename );
  60.                         Frename ( 0,"qqqq", filename );
  61.                   }
  62.           }
  63.   }
  64.